<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>npm相关 - ZzmHub Blog</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="ZzmHub" /><meta name="description" content="node.js下的包管理工具 镜像安装 国内网络环境下载包网速慢的处理 使用淘宝镜像 1 npm install -g cnpm --registry=https://registry.npm.taobao.org npm指向淘宝镜像 1 2 3 4 5 npm config set registry https://registry.npm.taobao.org/ //淘宝源 npm" /><meta name="keywords" content="Hugo, theme, even" />






<meta name="generator" content="Hugo 0.69.2 with theme even" />


<link rel="canonical" href="https://meilanziqing.gitee.io/zhi-blogs/post/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/npm%E7%9B%B8%E5%85%B3/" />
<link rel="apple-touch-icon" sizes="180x180" href="/zhi-blogs/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/zhi-blogs/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/zhi-blogs/favicon-16x16.png">
<link rel="manifest" href="/zhi-blogs/manifest.json">
<link rel="mask-icon" href="/zhi-blogs/safari-pinned-tab.svg" color="#5bbad5">



<link href="/zhi-blogs/sass/main.min.4eb71590ad024de2ebb1b5eef94cbb645b7e63e6b9c4c837355530a75e112ce1.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="npm相关" />
<meta property="og:description" content="node.js下的包管理工具 镜像安装 国内网络环境下载包网速慢的处理 使用淘宝镜像 1 npm install -g cnpm --registry=https://registry.npm.taobao.org npm指向淘宝镜像 1 2 3 4 5 npm config set registry https://registry.npm.taobao.org/ //淘宝源 npm" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://meilanziqing.gitee.io/zhi-blogs/post/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/npm%E7%9B%B8%E5%85%B3/" />
<meta property="article:published_time" content="2020-06-27T12:09:54+08:00" />
<meta property="article:modified_time" content="2020-06-27T12:09:54+08:00" />
<meta itemprop="name" content="npm相关">
<meta itemprop="description" content="node.js下的包管理工具 镜像安装 国内网络环境下载包网速慢的处理 使用淘宝镜像 1 npm install -g cnpm --registry=https://registry.npm.taobao.org npm指向淘宝镜像 1 2 3 4 5 npm config set registry https://registry.npm.taobao.org/ //淘宝源 npm">
<meta itemprop="datePublished" content="2020-06-27T12:09:54&#43;08:00" />
<meta itemprop="dateModified" content="2020-06-27T12:09:54&#43;08:00" />
<meta itemprop="wordCount" content="298">



<meta itemprop="keywords" content="npm," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="npm相关"/>
<meta name="twitter:description" content="node.js下的包管理工具 镜像安装 国内网络环境下载包网速慢的处理 使用淘宝镜像 1 npm install -g cnpm --registry=https://registry.npm.taobao.org npm指向淘宝镜像 1 2 3 4 5 npm config set registry https://registry.npm.taobao.org/ //淘宝源 npm"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/zhi-blogs/" class="logo">ZzmHub</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/zhi-blogs/">
        <li class="mobile-menu-item">首页</li>
      </a><a href="/zhi-blogs/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/zhi-blogs/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/zhi-blogs/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/zhi-blogs/about/">
        <li class="mobile-menu-item">关于</li>
      </a>
  </ul>
</nav>
  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/zhi-blogs/" class="logo">ZzmHub</a>
</div>

<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/zhi-blogs/">首页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/zhi-blogs/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/zhi-blogs/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/zhi-blogs/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/zhi-blogs/about/">关于</a>
      </li>
  </ul>
</nav>
    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">npm相关</h1>

      <div class="post-meta">
        <span class="post-time"> 2020-06-27 </span>
        <div class="post-category">
            <a href="/zhi-blogs/categories/%E5%B7%A5%E5%85%B7%E5%BA%94%E7%94%A8/"> 工具应用 </a>
            </div>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li><a href="#镜像安装">镜像安装</a></li>
    <li><a href="#包安装">包安装</a>
      <ul>
        <li><a href="#本地安装与全局安装">本地安装与全局安装</a></li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <p>node.js下的包管理工具</p>
<h2 id="镜像安装">镜像安装</h2>
<p>国内网络环境下载包网速慢的处理</p>
<ul>
<li>使用淘宝镜像</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">npm install -g cnpm --registry=https://registry.npm.taobao.org
</code></pre></td></tr></table>
</div>
</div><p>npm指向淘宝镜像</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">npm config set registry https://registry.npm.taobao.org/  //淘宝源

npm config set registry https://registry.npmjs.org/ //改回原始源 

npm config get registry //配置后可通过下面方式验证是否成功 
</code></pre></td></tr></table>
</div>
</div><h2 id="包安装">包安装</h2>
<h3 id="本地安装与全局安装">本地安装与全局安装</h3>
<p><code>全局安装</code>一般用于框架工具类的安装，如vue、 webpack等</p>
<ol>
<li>将安装包放在 /usr/local 下</li>
<li>可以直接在命令行里使用</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">npm i webpack -g    
</code></pre></td></tr></table>
</div>
</div><p><code>本地安装</code>一般用于项目依赖的安装，分为安装到开发环境、生产环境</p>
<ol>
<li>将安装包放在 ./node_modules 下（运行npm时所在的目录）</li>
<li>可以通过 require() 来引入本地安装的包</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">// 安装到开发环境,写入到 devDependencies 对象

npm i jquery --save-dev 

npm i jquery -D


//安装到生产环境,写入到 dependencies 对象

npm i jquery

npm i jquery --save

npm i jquery -S
</code></pre></td></tr></table>
</div>
</div>
    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">ZzmHub</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2020-06-27
        
    </span>
  </p>
  
  
</div>
<footer class="post-footer">
      <div class="post-tags">
          <a href="/zhi-blogs/tags/npm/">npm</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/zhi-blogs/post/vue/%E9%A1%B9%E7%9B%AE%E9%81%87%E5%88%B0%E7%9A%84bug/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">项目中bug收集</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/zhi-blogs/post/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/webpack/">
            <span class="next-text nav-default">webpack简单入门</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:gdmec.zhi@email.com" class="iconfont icon-email" title="email"></a>
      <a href="https://github.com/zhimianhub" class="iconfont icon-github" title="github"></a>
  <a href="https://meilanziqing.gitee.io/zhi-blogs/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy; 
    2017 - 
    2020
    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">ZzmHub</span>
  </span>
</div>
    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/zhi-blogs/js/main.min.d7b7ada643c9c1a983026e177f141f7363b4640d619caf01d8831a6718cd44ea.js"></script>








</body>
</html>
